package test.matchers;

import java.util.Collection;

import org.hamcrest.Description;
import org.hamcrest.Factory;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;

public class SizeMatcher extends TypeSafeMatcher<Collection<? extends Object>>
{
	private Matcher<Integer> matcher;
	
	public SizeMatcher(Matcher <Integer> matcher)
	{
		this.matcher = matcher;
	}

	public void describeTo(Description d) 
	{
		d.appendText("a collection with a size that is");
	}

	@Override
	public boolean matchesSafely(Collection<? extends Object> collection) 
	{
		return matcher.matches(collection.size());
	}
	
	@Factory
	public static Matcher<Collection<? extends Object>> hasSize(Matcher<Integer> matcher)
	{
		return new SizeMatcher(matcher);
	}

	

}
